package com.jie.deletefile.Listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.jie.deletefile.Listview.adapter.ShaAdapter;
import com.jie.deletefile.R;

import java.util.ArrayList;
import java.util.List;

public class ShaActivity extends AppCompatActivity implements View.OnClickListener {

    private Button sha_1;
    private ListView sha_lv1;
    private Button sha_2;
    private ListView sha_lv2;
    private List<String> data;
    private ShaAdapter adapter;
    private boolean showlv1;
    private boolean showlv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sha);
        initView();
    }

    private void initView() {
        sha_1 = (Button) findViewById(R.id.sha_1);
        sha_lv1 = (ListView) findViewById(R.id.sha_lv1);
        sha_2 = (Button) findViewById(R.id.sha_2);
        sha_lv2 = (ListView) findViewById(R.id.sha_lv2);
        data = new ArrayList<>();
        data.add("11111111111111111");
        data.add("222222222222222222");
        data.add("333333333333333333");

        adapter = new ShaAdapter(this, data);
        sha_lv1.setAdapter(adapter);
        sha_lv2.setAdapter(adapter);

        sha_1.setOnClickListener(this);
        sha_2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sha_1:
                if (showlv1) {
                    sha_lv1.setVisibility(View.GONE);
                    showlv1 = false;
                } else {
                    sha_lv1.setVisibility(View.VISIBLE);
                    showlv1 = true;
                }


                break;
            case R.id.sha_2:
                if (showlv2) {
                    sha_lv2.setVisibility(View.GONE);
                    showlv2 = false;
                } else {
                    sha_lv2.setVisibility(View.VISIBLE);
                    showlv2 = true;
                }

                break;
        }
    }
}
